package com.example.springboot008webmvcconfigurer.Interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @description: TODO
 * @author: uu
 * @data: 2023/7/4 上午 09:39
 * @version: v1.0
 */
public class AuthInterceptor implements HandlerInterceptor {
    private final String COMMON_USER = "cms";
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("====拦截器====");
        String loginUser = request.getParameter("loginUser");
        String requestURI = request.getRequestURI();
    if (COMMON_USER.equals(loginUser) && (requestURI.startsWith("/article/add")
    || requestURI.startsWith("/article/edit") || requestURI.startsWith("/article/query"))){
        return true;
    }
    return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}
